package com.qfjy.config.example4;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName ScanPayConfig
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/11/22
 * @Version 1.0
 */
@Configuration
public class ScanPayConfig {

    /**
     * 1、定义交换机 直连
     * 2、定义队列（微信、支付宝）
     * 3、进行绑定（交换机和队列+RoutingKey)
     */
    @Bean
    public DirectExchange scanPayDirectExchange(){

        return new DirectExchange("scanPayDirectExchange");
    }
    /**
     * 定义队列
     * 队列的命名要求：建议大家尽量用.的方式进行字符串分隔。
     *    要么用.要么不分隔。不允许用其它符号。
     */
    @Bean
    public Queue directWeixinQueue(){
        return new Queue("scanPay.direct.weixinQueue");
    }
    @Bean
    public Queue directZhifubaoQueue(){
        return new Queue("scanPay.direct.zhifubaoQueue");
    }

    @Bean
    public Binding bindWeixinQueue(Queue directWeixinQueue,DirectExchange scanPayDirectExchange){
        return BindingBuilder.bind(directWeixinQueue).to(scanPayDirectExchange).with("weixin");
    }
    @Bean
    public Binding bindZhifubaoQueue(Queue directZhifubaoQueue,DirectExchange scanPayDirectExchange){
        return BindingBuilder.bind(directZhifubaoQueue).to(scanPayDirectExchange).with("zhifubao");
    }
}
